import { createRouter, createWebHistory } from "vue-router";
import HomeView from "../views/HomeView.vue";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path:'/',
      redirect:'/start'
    },
    {
      path: "/homeview",
      component: HomeView,
      children: [
        {
          path: "/home",
          name: "home",
          component: () => import("../views/Home/index.vue"),
        },
        {
          path: "/map",
          name: "map",
          component: () => import("../views/Map/index.vue"),
        }, {
          path: "/cut",
          name: "cut",
          component: () => import("../views/Cut/index.vue"),
          children: [
            { path: '', name: 'aluse', component: () => import('@/views/Cut/Aluse.vue') },
            { path: "alwc", name: "alwc", component: () => import('@/views/Cut/Alwc.vue') },
            { path: "alqx", name: "alqx", component: () => import('@/views/Cut/Alqx.vue') },
          ]
        },

        {
          path: "/message",
          name: "message",
          component: () => import("../views/Message/index.vue"),
        },
        {
          path: "/my",
          name: "my",
          component: () => import("../views/My/index.vue"),
        },

      ],
    },
    // 门店路由
    {//门店首页
      path: "/shopfrontinfo",
      name: "info",
      component: () => import("../views/ShopFront/Info.vue")
    },
    {
      path: "/shopfrontabout",
      name: "about",
      component: () => import("../views/ShopFront/About/About.vue"),
      children: [
        { path: "guanyu", name: "guanyu", component: () => import('@/views/ShopFront/About/Guanyu.vue') },
        { path: "fuwu", name: "fuwu", component: () => import("@/views/ShopFront/About/Fuwu.vue") },
        { path: "taocan", name: "taocan", component: () => import('@/views/ShopFront/About/Taocan.vue') },
        { path: "xiangce", name: "xiangce", component: () => import('@/views/ShopFront/About/Xiangce.vue') },
        { path: "pingjia", name: "pingjia", component: () => import('@/views/ShopFront/About/Pingjia.vue') },
      ]
    },
    {
      path: "/shopfrontMyfuwu",
      name: "myfuwu",
      component: () => import("../views/ShopFront/Myfuwu.vue")
    },
    {//选择
      path: "/shopfrontxuanze",
      name: "xuanze",
      component: () => import("../views/ShopFront/About/Xuanze.vue")
    },
    {//预约
      path: "/shopfrontYuyue",
      name: "yuyue",
      component: () => import("../views/ShopFront/Yuyue.vue")
    },
    {//全部评价
      path: "/quanping",
      name: "quanping",
      component: () => import("../views/ShopFront/Quanpingjia.vue")
    },
    {//付款
      path: "/fukuan",
      name: "fukuan",
      component: () => import("../views/ShopFront/Fukuan.vue")
    },
    {//预约详情
      path: "/yuinfo",
      name: "yuinfo",
      component: () => import("../views/ShopFront/Yuinfo.vue")
    },
    //  付款详情页
    {
      path: "/fuxiang",
      name: "fuxiang",
      component: () => import("../views/ShopFront/Fuxiang.vue")
    },
    {//  发型师
      path: "/faxingshi",
      name: "faxingshi",
      component: () => import("../views/ShopFront/Faxingshi.vue")
    },
    {//套餐详情
      path: "/taocaninfo",
      name: "taocaninfo",
      component: () => import("../views/ShopFront/Taocaninfo.vue")
    },
    {//订单评价
      path: "/detail",
      name: "detail",
      component: () => import("../views/Cut/Detail.vue"),
    },
    {
      path: '/start',
      name: 'start',
      component: () => import('../views/Login/Start.vue')
    },
    {
      path: '/guide',
      name: 'guide',
      component: () => import('../views/Login/Guide.vue')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/Login/Login.vue')
    }, {
      path: '/chatroom',
      name: 'chatroom',
      component: () => import('../views/Message/chatRoom.vue'),
    }, {
      path: '/way',
      name: 'way',
      component: () => import('../views/Login/Loginway.vue')
    },
    {
      path: '/createuser',
      name: 'createuser',
      component: () => import('../views/Login/CreateU.vue')
    },
    {
      path: '/person',
      name: 'person',
      component: () => import('../views/Login/Person.vue')
    },
    {
      path: '/forgot',
      name: 'forgot',
      component: () => import('../views/Login/Forgot.vue')
    },
    {
      path: '/code',
      name: 'code',
      component: () => import('../views/Login/Code.vue')
    },
    {
      path: '/createpwd',
      name: 'createpwd',
      component: () => import('../views/Login/CreatePwd.vue')
    },
    {
      path: '/phone',
      name: 'phone',
      component: () => import('../views/Login/Phone.vue')
    }, {
      path: '/payment',
      name: 'payment',
      component: () => import('../views/My/payment.vue')
    },
    {
      path: '/safe',
      name: 'safe',
      component: () => import('../views/My/safe.vue')
    },
    {
      path: '/language',
      name: 'language',
      component: () => import('../views/My/language.vue')
    }, {
      path: '/notice',
      name: 'notice',
      component: () => import('../views/My/notice.vue')
    }, {
      path: '/cache',
      name: 'cache',
      component: () => import('../views/My/cache.vue')
    }, {
      path: '/privacy',
      name: 'privacy',
      component: () => import('../views/My/privacy.vue')
    }, {
      path: '/we',
      name: 'we',
      component: () => import('../views/My/we.vue')
    }, {
      path: '/article',
      name: 'article',
      component: () => import('../views/My/article.vue')
    }, {
      path: '/changeinfo',
      name: 'changeinfo',
      component: () => import('../views/My/changeinfo.vue')
    },
    {
      path: "/ss",
      name: "ss",
      component: () => import("../views/Home/ss.vue"),
    },
    {
      path: "/huoqu",
      name: "huoqu",
      component: () => import("../views/Map/huoqu.vue"),
    },
    {
      path: "/ss_show",
      name: "ss_show",

      component: () => import("../views/Home/ss_show.vue"),
    },
    {
      path: "/show",
      name: "show",
      component: () => import("../views/Home/show.vue"),
    },
    {
      path: "/fjmd",
      name: "fjmd",
      component: () => import("../views/Home/fjmd.vue"),
    },
    {
      path: "/tz",
      name: "tz",
      component: () => import("../views/Home/tz.vue"),
    },
    {
      path: "/aaaa",
      name: "aaaa",
      component: () => import("../views/Map/aaaa.vue"),
    },
  ],
});


router.beforeEach((to, from, next) => {
  // 路由拦截
  if (to.path === '/login' || to.path === '/start' || to.path === '/guide' || to.path === '/forgot' || to.path === '/code' || to.path === '/person' || to.path === '/createuser' || to.path === '/createpwd' || to.path === '/phone' || to.path === '/way' ) {
    next();
  } else {
    const accessToken = localStorage.getItem('accessToken');
    const phone = localStorage.getItem('phone');
    if (accessToken || phone) {
      next();
    } else {
      next('/login')
}}})

export default router;
